﻿using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.GraphicsInterface;
namespace CADTool
{
    public class Flash
    {
        public FlashEntity flash=null;
        public Entity _ent=null;
        public Flash(Entity ent)
        {
            _ent = ent;
            flash = new FlashEntity(ent);
            Transient.CapturedDrawable = flash;
            TransientManager.CurrentTransientManager.AddTransient(flash, TransientDrawingMode.Main, 128,
                new IntegerCollection());
        }
        public void FlashUpdate(Entity ent)
        {
            if (flash == null)
            {
                _ent = ent;
                flash = new FlashEntity(ent);
                Transient.CapturedDrawable = flash;
                TransientManager.CurrentTransientManager.AddTransient(flash, TransientDrawingMode.Main, 128,
                    new IntegerCollection());
            }
            else
            {
                _ent = ent;
                flash._ent=ent;
                TransientManager.CurrentTransientManager.UpdateTransient(flash,new IntegerCollection());
            }
        }
        public void FlashErase()
        {
            if (flash == null) return;
            flash._ent= null;
            TransientManager.CurrentTransientManager.EraseTransient(flash, new IntegerCollection());
            flash._ent=null;
        }
    }
    public class FlashEntity : Transient
    {
        public Entity _ent;
        public FlashEntity(Entity ent)
        {
            _ent = ent;
        }
        protected override int SubSetAttributes(DrawableTraits traits)
        {
            traits.FillType = FillType.FillAlways;
            return (int)DrawableAttributes.IsAnEntity;
        }

        protected override void SubViewportDraw(ViewportDraw vd)
        {
            vd.Geometry.Draw(_ent);
            System.Drawing.Point pt = System.Windows.Forms.Cursor.Position;
            System.Windows.Forms.Cursor.Position=new System.Drawing.Point(pt.X, pt.Y);
        }
        /// <summary>
        /// SubWorldDraw方法的返回值表示该瞬态对象是否在AutoCAD世界坐标系中绘制。
        /// 如果返回true，则表示该瞬态对象是一个不透明的实体对象，会被保存到数据库中。
        /// 如果返回false，则表示该瞬态对象只在AutoCAD视口中显示出来，不会保存到数据库中。
        /// </summary>
        /// <param name="wd"></param>
        /// <returns></returns>
        protected override bool SubWorldDraw(WorldDraw wd)
        {
            return false;
        }
    }
}

